/* Default (Light Mode) Variables */

:root {
  --body-bg: #f4f4f4;
  --content-bg: #fff;
  --tab-bar-bg: #e9ecef;
  --tab-hover-bg: #dee2e6;
  --border-color: #ccc;
  --light-border-color: #eee;
  --text-color: #333;
  --secondary-text-color: #495057;
  --tertiary-text-color: #6c757d;
  --tab-hover-text-color: #343a40;
  --accent-color: #007bff;
  --accent-hover-color: #0056b3;
  --accent-text-color: white;
  --disabled-bg: #6c757d;
  --disabled-text: #dee2e6;
  --bubble-bg: #e9ecef;
  --code-bg: #dee2e6;
  --pre-bg: #343a40;
  --pre-text: #f8f9fa;
  --blockquote-border: #adb5bd;
  --blockquote-bg: #f8f9fa;
  --guide-strong-color: #d9534f;
  --status-success: #28a745;
  --status-warning: #ffc107;
  --status-error: #dc3545;
  --user-icon-color: var(--accent-color);
  --logo-filter: none;
}

/* Dark Mode Variables */

@media (prefers-color-scheme: dark) {
  :root {
    --body-bg: #121212;
    --content-bg: #1e1e1e;
    --tab-bar-bg: #252526;
    --tab-hover-bg: #383838;
    --border-color: #444;
    --light-border-color: #333;
    --text-color: #e0e0e0;
    --secondary-text-color: #adb5bd;
    --tertiary-text-color: #999;
    --tab-hover-text-color: #f1f1f1;
    --accent-color: #3b82f6;
    --accent-hover-color: #60a5fa;
    --accent-text-color: #fff;
    --disabled-bg: #555;
    --disabled-text: #aaa;
    --bubble-bg: #3a3a3a;
    --code-bg: #4a4a4a;
    --pre-bg: #2d2d2d;
    --pre-text: #d4d4d4;

    /* Code block text */
    --blockquote-border: #555;
    --blockquote-bg: #2a2a2a;
    --guide-strong-color: #f47272;

    /* Lighter red */
    --status-success: #4ade80;

    /* Brighter green */
    --status-warning: #facc15;

    /* Brighter yellow */
    --status-error: #f87171;

    /* Brighter red */
    --user-icon-color: var(--accent-hover-color);
    --logo-filter: invert(1) hue-rotate(180deg);
  }
}

/* ----- BASE & ELEMENT STYLES ---------- */
body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  margin: 0;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  background-color: var(--body-bg);
  color: var(--text-color);
}

/* --- Tab Styles --- */
.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  background-color: var(--tab-bar-bg);
}

.tab-button {
  padding: 10px 18px;
  cursor: pointer;
  border: none;
  background-color: transparent;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  font-size: 1em;
  font-weight: 500;
  color: var(--secondary-text-color);
  transition:
    background-color 0.2s ease,
    border-bottom-color 0.2s ease,
    color 0.2s ease;
}

.tab-button.active {
  border-bottom-color: var(--accent-color);
  color: var(--accent-hover-color);
  font-weight: bold;
  background-color: var(--content-bg);
}

.tab-button:hover:not(.active) {
  background-color: var(--tab-hover-bg);
  color: var(--tab-hover-text-color);
}

.tab-content {
  flex-grow: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  background-color: var(--content-bg);
}

.tab-panel {
  display: none;
  height: 100%;
  width: 100%;
  overflow: hidden;
  flex-direction: column;
  padding: 15px;
  box-sizing: border-box;
}

.tab-panel.active {
  display: flex;
}

/* --- Original App Styles (within .app-container) --- */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.header-container {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  padding: 10px 0;
  margin-bottom: 1em;
  border-bottom: 1px solid var(--light-border-color);
}

.logo {
  height: 40px;
  width: auto;
  margin-right: 15px;
  filter: var(--logo-filter);
}

.header-container h1 {
  margin: 0;
  font-size: 1.5em;
  color: var(--text-color);
}

#messages {
  flex-grow: 1;
  flex-shrink: 1;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 10px;
  background-color: var(--content-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 1em;
}

/* Message Bubble Styles - Using Variables */

.message-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.message-wrapper.user {
  width: 100%;
  flex-direction: row-reverse;
}

.message-wrapper.server,
.message-wrapper.thinking {
  align-self: flex-start;
  flex-direction: row;
  max-width: 85%;
  width: fit-content;
}

.message-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.message-icon.robot-icon img {
  width: 35px;
  height: 35px;
  display: block;
  border-radius: 50%;
}

.message-icon.user-icon {
  font-size: 1.5em;
  padding-top: 0;
  color: var(--user-icon-color);
}

.message-bubble {
  padding: 10px 15px;
  border-radius: 15px;
  word-wrap: break-word;
  margin: 0;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
}

.message-bubble.user-message {
  background-color: var(--accent-color);
  color: var(--accent-text-color);
  margin-left: auto;
  max-width: 85%;
  border-bottom-right-radius: 5px;
}

.message-bubble.server-message-block {
  background-color: var(--bubble-bg);
  color: var(--text-color);
  border-bottom-left-radius: 5px;
}

.message-bubble.thinking-bubble {
  background-color: var(--bubble-bg);
  color: var(--tertiary-text-color);
  font-style: italic;
  padding: 10px 15px;
}

.thinking-bubble .dots span {
  display: inline-block;
  opacity: 0;
  animation: blink 1.4s infinite;
}

.thinking-bubble .dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-bubble .dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0% {
    opacity: 0;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

#messages > .system-status-message {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-style: italic;
  color: var(--tertiary-text-color);
  background-color: transparent;
  border: none;
  padding: 8px 12px;
  margin: 5px 0;
  font-size: 0.9em;
}

.connection-open-text {
  color: var(--status-success);
  font-weight: bold;
}

.connection-closed-text {
  color: var(--status-warning);
  font-weight: bold;
}

.error-text {
  color: var(--status-error);
  font-weight: bold;
}

/* Styles for markdown content within bubbles - Using Variables */

.message-bubble code {
  background-color: var(--code-bg);
  color: var(--text-color);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: "Courier New", Courier, monospace;
  word-wrap: break-word;
  font-size: 0.9em;
}

.message-bubble pre {
  background-color: var(--pre-bg);
  color: var(--pre-text);
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  max-width: 100%;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9em;
}

.message-bubble pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
}

/* Inherit pre color */

.message-bubble blockquote {
  border-left: 4px solid var(--blockquote-border);
  padding-left: 12px;
  margin-left: 0;
  color: var(--secondary-text-color);
  font-style: italic;
  background-color: var(--blockquote-bg);
}

.message-bubble ul,
.message-bubble ol {
  margin-left: 20px;
  padding-left: 5px;
  overflow: hidden;
  margin-top: 5px;
  margin-bottom: 5px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  margin-top: 10px;
  margin-bottom: 5px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--light-border-color);
  color: var(--text-color);
}

.message-bubble a {
  color: var(--accent-hover-color);
  text-decoration: underline;
}

#message-form {
  flex-shrink: 0;
  padding: 10px 0;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--light-border-color);

  /* USE VARIABLE */
}

#message {
  flex-grow: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1em;
  background-color: var(--content-bg);
  color: var(--text-color);
}

#send-button {
  background-color: var(--accent-color);

  /* USE VARIABLE */
  color: var(--accent-text-color);

  /* USE VARIABLE */
  border: none;
  padding: 8px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.2s ease;
}

#send-button:disabled {
  background-color: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

#send-button:hover:not(:disabled) {
  background-color: var(--accent-hover-color);
}

/* --- User Guide Tab Styles - Using Variables --- */

#user-guide-tab-content {
  overflow-y: auto;
  line-height: 1.7;
  color: var(--text-color);
}

#user-guide-markdown-content {
  padding: 10px 20px;
}

#user-guide-markdown-content h1,
#user-guide-markdown-content h2,
#user-guide-markdown-content h3 {
  color: var(--accent-hover-color);
  border-bottom: 1px solid var(--light-border-color);
  padding-bottom: 5px;
  margin-top: 1.5em;
  margin-bottom: 0.8em;
}

#user-guide-markdown-content strong {
  color: var(--guide-strong-color);
}

#user-guide-markdown-content code {
  background-color: var(--code-bg);
  color: var(--text-color);
  padding: 3px 6px;
  border-radius: 3px;
  font-family: "Courier New", Courier, monospace;
}

#user-guide-markdown-content pre {
  background-color: var(--pre-bg);
  color: var(--pre-text);
  padding: 15px;
  border-radius: 4px;
  overflow-x: auto;
}

#user-guide-markdown-content blockquote {
  border-left: 5px solid var(--blockquote-border);
  padding-left: 15px;
  margin-left: 0;
  color: var(--secondary-text-color);
  background-color: var(--blockquote-bg);
  font-style: italic;
}

#user-guide-markdown-content a {
  color: var(--accent-hover-color);
  text-decoration: underline;
}
